package logic

import (
	"context"
	"rent/rentrpc/rentrpc"

	"rent/api/internal/svc"
	"rent/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.UpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	Update, err := l.svcCtx.RentRpc.Update(l.ctx, &rentrpc.UpdateRequest{
		Tel:         req.Tel,
		Password:    req.Password,
		Newpassword: req.Newpassword,
		Id:          int64(req.Id),
		Sendsms:     req.Sendsms,
		Source:      req.Source,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    "500",
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Data:    Update,
		Code:    "200",
	}, nil

}
